<template>
  <div class="container">
    <div class="title">
      <span v-if="!projectParams.pid">项目信息</span>
      <span v-else>{{formData.project_name}}——{{formData.project_code}}</span>
    </div>
    <el-form :model="formData" ref="form" label-position="top" :rules="rules" :inline="false" size="normal">
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="项目名称" prop="project_name">
            <el-input v-model="formData.project_name" placeholder="项目名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="是否通过发改委立项" prop="check_flag">
            <el-radio-group v-model="formData.check_flag">
              <el-radio-button label="0" border>未立项</el-radio-button>
              <el-radio-button label="1" border>立项</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item :label="formData.check_flag==1?'立项批复文号':'财政局指标文或技术审核文号'" prop="document_code">
            <el-input v-model="formData.document_code" :placeholder="formData.check_flag==1?'立项批复文号':'财政局指标文或技术审核文号'">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="项目建设模式" prop="project_model">
            <el-select v-model="formData.project_model" value-key="project_model" placeholder="请选择" class="wid">
              <el-option v-for="item in d_buildType" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="项目采购方式" prop="procurement_method">
            <el-select v-model="formData.procurement_method" value-key="procurement_method" placeholder="请选择"
              class="wid">
              <el-option v-for="item in d_purchaseType" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="公安局备案等级保护级别" prop="project_grade">
            <el-select v-model="formData.project_grade" value-key="project_grade" placeholder="请选择" class="wid">
              <el-option v-for="item in d_levelProtect" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="项目建设部门" prop="department">
            <el-input v-model="formData.department" placeholder="项目建设部门"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="项目建设联系人" prop="contacts">
            <el-input v-model="formData.contacts" placeholder="项目建设联系人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="项目建设联系人电话" prop="contact_mobile">
            <el-input v-model="formData.contact_mobile" placeholder="项目建设联系人电话"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="项目运维申请部门" prop="maintenance_department">
            <el-input v-model="formData.maintenance_department" placeholder="项目运维申请部门"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="项目运维申请部门联系人" prop="maintenance_contacts">
            <el-input v-model="formData.maintenance_contacts" placeholder="项目运维申请部门联系人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="项目运维申请部门联系人电话" prop="maintenance_contacts_mobile">
            <el-input v-model="formData.maintenance_contacts_mobile" placeholder="项目运维申请部门联系人电话"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="项目总投资金额" prop="amount">
            <el-input v-model="formData.amount" placeholder="项目总投资金额">
              <span slot="append">万元</span>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="建成时间" prop="create_time">
            <el-date-picker v-model="formData.create_time" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"
              :clearable="false" class="wid">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="项目运维申报情况" prop="maintenance_type">
            <el-select v-model="formData.maintenance_type" value-key="maintenance_type" placeholder="请选择" class="wid">
              <el-option v-for="item in d_declareType" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0" v-if="formData.maintenance_type =='2' || formData.maintenance_type=='3'">
          <el-form-item label="以往项目运维资金来源" prop="maintain_amount_source">
            <el-select v-model="formData.maintain_amount_source" value-key="maintain_amount_source" placeholder="请选择"
              class="wid">
              <el-option v-for="item in d_declarePastType" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0"
          v-if="(formData.maintenance_type =='2' || formData.maintenance_type=='3') &&  formData.maintain_amount_source >=10">
          <el-form-item label="具体资金来源" prop="maintain_amount_source_custom">
            <el-input v-model="formData.maintain_amount_source_custom" :placeholder="formData.maintain_amount_source ==='10'?'请填写政府专项具体资金来源':
            (formData.maintain_amount_source ==='11'?'请填写上级资金具体资金来源':'请填写其他具体资金来源')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24" :offset="0">
          <el-form-item label="使用情况" prop="context">
            <el-input v-model="formData.context" placeholder="使用情况" size="normal" clearable type="textarea" :rows="4">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="title">项目附件</div>
      <el-row :gutter="20">
        <el-col :span="6" :offset="0" v-if="formData.check_flag == 0">
          <el-form-item prop="check_file">
            <up-load titleName="财政局指标文/大数据局(经信委)技术审核文件" :size="50" :require="true" v-model="formData.check_file">
            </up-load>
          </el-form-item>
          <el-button type="primary" size="medium" @click="dsjShow = true" v-if="this.switch">查看示例</el-button>
        </el-col>
        <el-col :span="6" :offset="0" v-if="formData.check_flag == 1">
          <el-form-item prop="document_url">
            <up-load titleName="发改委批复文件" :size="50" :require="true" v-model="formData.document_url"></up-load>
          </el-form-item>
          <el-button type="primary" size="medium" @click="fgwShow = true" v-if="this.switch">查看示例</el-button>
        </el-col>
        <el-col :span="6" :offset="0">
          <el-form-item prop="records_file">
            <up-load titleName="等（分）保备案证书" :size="50" v-model="formData.records_file"></up-load>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="0">
          <el-form-item prop="evaluation_file">
            <up-load titleName="漏扫或等保测评报告" :size="50" v-model="formData.evaluation_file"></up-load>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="0">
          <el-form-item prop="doc_url">
            <up-load titleName="源代码及其技术文档" :size="50" v-model="formData.doc_url" :accept="['pdf', 'rar', 'zip']">
            </up-load>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="center">
      <el-button type="danger" @click="projectCancel" :loading="saveLoading">取消</el-button>
      <template v-if="this.switch && this.copyStatus!='0'">
        <el-button type="primary" @click="projectEdit" :loading="saveLoading" v-if="projectParams.pid">修改</el-button>
        <el-button type="primary" @click="projectAdd" :loading="saveLoading" v-else>添加</el-button>
      </template>
    </div>
    <!-- 财政局指标文/大数据局(经信委)技术审核文件 -->
    <el-dialog title="财政局指标文/大数据局(经信委)技术审核文件" :visible.sync="dsjShow" width="70%" @close="dsjShow = false"
      append-to-body top="0">
      <img src="@/assets/images/example/caizhengzhibiaowen.png" class="wid">
      <img src="@/assets/images/example/dashuju1.png" class="wid">
      <img src="@/assets/images/example/dashuju2.png" class="wid">
      <span slot="footer">
        <el-button type="danger" @click="dsjShow = false">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 发改委立项批复文件 -->
    <el-dialog title="发改委立项批复文件" :visible.sync="fgwShow" width="70%" @close="fgwShow = false" append-to-body top="0">
      <img src="@/assets/images/example/fagaiwei1.png" class="wid">
      <img src="@/assets/images/example/fagaiwei2.png" class="wid">
      <img src="@/assets/images/example/fagaiwei3.png" class="wid">
      <span slot="footer">
        <el-button type="danger" @click="fgwShow = false">关闭</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
import UpLoad from '../Upload'
import { d_buildType, d_purchaseType, d_levelProtect, d_declareType, d_declarePastType } from '@/utils/dicts.js'
export default {
  name: 'Project',
  components: {
    UpLoad
  },
  props: {
    projectParams: {
      type: Object,
      default: () => {
        return {}
      }
    },
    switch: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    copyStatus: {
      type: String,
      default: () => {
        return '3'
      }
    }
  },
  data () {
    return {
      saveLoading: false,
      formData: {
        check_flag: '0',
      },
      rules: {
        project_name: [
          { required: true, message: '请输入项目名称', trigger: 'blur' },
        ],
        check_flag: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        document_code: [
          { required: true, message: '请输入立项批复文号', trigger: 'blur' }
        ],
        project_model: [
          { required: true, message: '请选择项目建设模式', trigger: 'change' }
        ],
        procurement_method: [
          { required: true, message: '请选择项目采购方式', trigger: 'change' }
        ],
        project_grade: [
          { required: true, message: '请选择公安局备案等级保护级别', trigger: 'change' }
        ],
        department: [
          { required: true, message: '请输入项目建设部门', trigger: 'blur' }
        ],
        contacts: [
          { required: true, message: '请输入项目建设联系人', trigger: 'blur' }
        ],
        contact_mobile: [
          { required: true, message: '请输入项目建设联系人电话', trigger: 'blur' }
        ],
        maintenance_department: [
          { required: true, message: '请输入项目运维申请部门', trigger: 'blur' }
        ],
        maintenance_contacts: [
          { required: true, message: '请输入项目运维申请部门联系人', trigger: 'blur' }
        ],
        maintenance_contacts_mobile: [
          { required: true, message: '请输入项目运维申请部门联系人电话', trigger: 'blur' }
        ],
        amount: [
          { required: true, validator: this.$util.isFloat, trigger: 'blur' }
        ],
        create_time: [
          { required: true, message: '请选择建成时间', trigger: 'change' }
        ],
        maintenance_type: [
          { required: true, message: '请选择项目运维申报情况', trigger: 'change' }
        ],
        maintain_amount_source: [
          { required: true, message: '请选择以往项目运维资金来源', trigger: 'change' }
        ],
        maintain_amount_source_custom: [
          { required: true, message: '请输入具体资金来源', trigger: 'blur' }
        ],
        context: [
          { required: true, message: '请输入使用情况', trigger: 'blur' }
        ],
        check_file: [
          { required: true, message: '请选择大数据局(经信委)技术审核文件', trigger: 'blur' }
        ],
        document_url: [
          { required: true, message: '请选择发改委批复文件', trigger: 'blur' }
        ],
      },
      d_buildType: d_buildType,
      d_purchaseType: d_purchaseType,
      d_levelProtect: d_levelProtect,
      d_declareType: d_declareType,
      d_declarePastType: d_declarePastType,
      dsjShow: false,
      fgwShow: false,
    }
  },
  created () {

  },
  mounted () {
    if (this.projectParams.pid) {
      this.init()
    }
  },
  methods: {
    async init () {
      this.saveLoading = true
      const res = await this.$http('inputProjectObj', {
        id: this.projectParams.pid
      })
      this.formData = res
      this.saveLoading = false
    },
    projectCancel () {
      this.$emit('cancel')
    },
    async projectEdit () {
      this.saveLoading = true
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          const res = await this.$http('inputProjectUp', {
            ...this.formData
          })
          if (res.errcode === 4000) {
            this.$tips.declareUp(res.errmsg)
          } else if (res.errcode === 9999) {
            this.$tips.error(res.errmsg)
          } else {
            this.$tips.success(res.errmsg)
          }
          this.saveLoading = false
          this.$emit('cancel')
          this.$emit('init')
        } else {
          this.$tips.error('请检查必填项')
          this.saveLoading = false
          return false;
        }
      });
    },
    async projectAdd () {
      this.saveLoading = true
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          const res = await this.$http('inputProjectAdd', {
            del_flag: '0',
            status: '0',
            project_nature: '0',
            check_status: '1',
            copy_status: '2',
            ...this.formData
          })
          this.$tips.success(res.errmsg)
          this.saveLoading = false
          this.$emit('cancel')
          this.$emit('init')
        } else {
          this.$tips.error('请检查必填项')
          this.saveLoading = false
          return false;
        }
      });
    },
  },
  computed: {

  },
  watch: {

  }
}
</script>
<style lang='scss' scoped>
</style>
